package com.niit.maxandmin;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @author:Ys
 * @date: 2022年09月17日 16:34
 * @desc:
 */
public class MaxAndMinValue implements WritableComparable<MaxAndMinValue> {

    private LongWritable min; //最小值
    private LongWritable max; //最大值
    private IntWritable total; //统计次数

    public MaxAndMinValue() {
        this.min = new LongWritable(0);
        this.max = new LongWritable(0);
        this.total = new IntWritable(0);
    }

    public MaxAndMinValue(long min,long max,int total){
        this.min = new LongWritable(min);
        this.max = new LongWritable(max);
        this.total = new IntWritable(total);
    }

    public LongWritable getMin() {
        return min;
    }

    public void setMin(LongWritable min) {
        this.min = min;
    }

    public LongWritable getMax() {
        return max;
    }

    public void setMax(LongWritable max) {
        this.max = max;
    }

    public IntWritable getTotal() {
        return total;
    }

    public void setTotal(IntWritable total) {
        this.total = total;
    }

    @Override
    public String toString() {
        return min.get() +"\t"+max.get()+"\t"+total.get();
    }

    @Override
    public void write(DataOutput out) throws IOException {
       this.min.write(out);
       this.max.write(out);
       this.total.write(out);
    }

    //反序列化的顺序 必要和 序列化的顺序保持一致
    @Override
    public void readFields(DataInput in) throws IOException {
        this.min.readFields(in);
        this.max.readFields(in);
        this.total.readFields(in);
    }
    //用于做Key的比较方法
    @Override
    public int compareTo(MaxAndMinValue o) {
        return 0;
    }
}
